package com.cqcetbbs.smartlab.cqcetbbs.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cqcetbbs.smartlab.cqcetbbs.R;

/**
 * Created by user on 2017/10/31.
 */

public class MytitleView extends RelativeLayout {

    String title;
    int textSize;
    View view;
    TextView tv_title;
    Context context;


    public MytitleView(Context context) {
        this(context, null);
    }

    public MytitleView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public MytitleView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.MytitleView);
        title = ta.getString(R.styleable.MytitleView_title);
        textSize = ta.getInteger(R.styleable.MytitleView_textSize, 20);
        ta.recycle();
        initView();
    }

    private void initView() {
        view = View.inflate(context, R.layout.title_layout, this);
        tv_title = view.findViewById(R.id.my_title);
        tv_title.setText(title);
        ImageView cmapus_back = view.findViewById(R.id.cmapus_back);

        cmapus_back.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onBackListener != null) {
                    onBackListener.onBack();
                }
            }
        });
    }

    public void setTitle(String title) {
        tv_title.setText(title);
    }

    onBackListener onBackListener;

    public interface onBackListener {
        void onBack();
    }

    public void setonBackListener(onBackListener onBackListener) {
        this.onBackListener = onBackListener;
    }


}
